package com.example.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.resource.BrokerageList;
import com.yijiu.trb.R;

/**
 * 佣金列表适配器
 * 
 * @author TangChao
 */
public class BrokerageListAdapter extends MyBaseAdapter
{
	private Context context;
	private View progressBar;
	
	public BrokerageListAdapter(List<BrokerageList> list, Context context)
	{
		super();
		this.list = list;
		this.context = context;
	}
	@Override
	public int getCount()
	{
		if (isShowProgress)
		{
			return list.size() + 1;
		}
		return list.size();
	}
	@Override
	public Object getItem(int arg0)
	{
		if (isShowProgress)
		{
			return null;
		}
		return list.get(arg0);
	}
	@Override
	public long getItemId(int arg0)
	{
		return arg0;
	}
	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2)
	{
		if (arg0 == list.size())
		{
			if (progressBar == null)
			{
				progressBar = LayoutInflater.from(context).inflate(R.layout.load_next_page_layout, null);
			}
			return progressBar;
		}
		else
		{
			arg1 = LayoutInflater.from(context).inflate(R.layout.brokerage_layout, null);
			TextView investor_name = (TextView) arg1.findViewById(R.id.investor_name);
			TextView investor_money = (TextView) arg1.findViewById(R.id.investor_money);
			TextView income = (TextView) arg1.findViewById(R.id.income);
			BrokerageList brokerageList = (BrokerageList) list.get(arg0);
			investor_name.setText(brokerageList.investorName);
			investor_money.setText("￥" + brokerageList.investAmount);
			income.setText("￥" + brokerageList.brokerBenifitAmount);
			if (arg0 >= list.size() - 1 && listener != null)
			{
				listener.onFoot();
			}
			return arg1;
		}
	}
}
